import pygame
import modGame

class MyGame:
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("三架飞机")
        self._screen = pygame.display.set_mode((800, 600))
        self._timer = pygame.time.Clock()
        self._margin = 8

        self._jets = []
        for i in range(3):
            self._jets.append(modGame.Jet())
    
    def play(self):
        self._set_jets_pos()

        keep_going = True
        while keep_going:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    keep_going = False
            
            self._screen.fill((0, 0, 0))
            # 飞机
            for jet in self._jets:
                jet.render(self._screen)

            pygame.display.update()
            self._timer.tick(60)

        pygame.quit()
    
    def _set_jets_pos(self):
        jetW = self._jets[0].width
        jetL = self._jets[0].length
        # 第一架飞机居中
        jetX = (self._screen.get_width() - jetW) / 2 # 水平居中
        jetY = self._screen.get_height() - self._margin - jetL # 垂直靠底部
        self._jets[0].SetPositon(jetX, jetY) # 设定飞机的初始位置
        # 第二架飞机偏左
        self._jets[1].SetPositon(jetX - jetW - self._margin, jetY)
        # 第三架架飞机偏右
        self._jets[2].SetPositon(jetX + jetW + self._margin, jetY)

myGame = MyGame()
myGame.play()